//fopen/fread/fwrite/fclose 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
   // FILE* fp = fopen("file.txt","w");
   // if(!fp)
   // {
   //     perror("open failed!\n");
   //     return 1;
   // }

   // char buffer[12] = "hello,linux";
   // //将buffer中的内容写到fp中
   // size_t size = fwrite(buffer,sizeof(char),strlen(buffer), fp);
   // printf("have written %zu words\n",size);

    //使用fread需要打开文件的时候用r选项
    FILE* fp = fopen("file.txt","r");
    if(!fp)
    {
        perror("open failed!\n");
        return 1;
    }
    //char* arr = (char*)malloc(100);
    char arr[20] = {0}; 
    //size_t num = fread(arr, sizeof(char),fp);
    //size_t num = fread(arr, sizeof(char),9,stdin);
    //procintf("read words:%zu, content is: %s",num, arr);

    //将后面的字符读取到内存缓冲区arr中，大小为10
    snprintf(arr,10,"%s","snprintf use");
    printf("snprintf：%s\n", arr);
    
    return 0;
}
